<?php
$query = $_GET["query"];
if(!isset($query)) {
    $query = "";
}
$markup = <<<EOL
<html>
    <head>
        <title>UniWiki</title>
        <link rel="stylesheet" href="http://yui.yahooapis.com/3.3.0/build/cssreset/reset.css" type="text/css">
        <link rel="stylesheet" href="http://yui.yahooapis.com/3.3.0/build/cssfonts/fonts.css" type="text/css">
        <link rel="stylesheet" href="http://yui.yahooapis.com/3.3.0/build/cssgrids/grids.css" type="text/css"> 
        <link rel="stylesheet" href="uniwiki.css" type="text/css"> 
        <script type="text/javascript" src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>

        
    </head>
    <body class="yui3-skin-sam  yui-skin-sam">
        <form action="uniwiki.php" method=GET>
            <input type="text" id="query" name="query" value="{$query}" />
            <input type="submit" id="sbutton" value="Submit" />
        </form>
EOL;

if($query) {
    $query = $_GET["query"];
    $username='c5980S11u17';
    $password='4610';
    $database='c5980S11u17';

    $link = mysql_connect('db.cselabs.umn.edu:3313',$username,$password);
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    $db_selected = mysql_select_db($database) or die( "Unable to select database");
    if (!$db_selected) {
        die ('Can\'t use foo : ' . mysql_error());
    }

    $query = "SELECT * from uni_wiki_info WHERE uni_name='$query'";
    $result = mysql_query($query);
    if (mysql_num_rows($result) == 0) {
        echo "No rows found, nothing to print so am exiting";
        exit;
    }
    $row = mysql_fetch_assoc($result);
    $markup .= <<<EOL
        <div class="yui3-g" id="layout">
            <div class="yui3-u" id="nav">
                <div class="content">
                    <h1>About {$row["uni_name"]}</h1>
                    <div id="description">
                        <div id="loading"></div>
                    </div>
                </div>

            </div>

            <div class="yui3-u" id="main">
                <div id="map_canvas" class="content"></div>
            </div>

        </div>
        <div id="tabs"></div>
        <div id="uni_name" class="param">{$row["uni_name"]}</div>
        <div id="latitude" class="param"> {$row["lat"]}</div>
        <div id="longitude" class="param"> {$row["lng"]}</div>
        <div id="wiki_link" class="param">{$row["wiki_link"]}</div>

EOL;
}

$markup .= <<<EOL
        <script type="text/javascript" src="uniwiki.js"></script>
    </body>
</html>
EOL;

echo $markup;
?>
